<!DOCTYPE html>
<html>
   <head>
      <title></title>
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
      <link rel="StyleSheet" type="text/css" href="/tpa/admin.css" />
      <link rel="StyleSheet" type="text/css" href="/tpa/jquery-ui.css" />
      <link rel="StyleSheet" type="text/css" href="/tpa/jquery.Jcrop.css" />
      <style type="text/css">
         span.removetab {
            cursor: pointer;
            float: right;
         }
      </style>

      <script type="text/javascript" src="/lib/js/jquery.js"></script>
      <script type="text/javascript" src="/lib/js/jquery.ui.js"></script>
      <script type="text/javascript" src="/lib/js/jquery.maskedinput.js"></script>
      <script type="text/javascript" src="/lib/js/meccano.js"></script>
      <script type="text/javascript" src="/lib/js/jquery.validate.js"></script>
      <script type="text/javascript" src="/lib/js/jquery.Jcrop.js"></script>
      <script type="text/javascript" src="/lib/js/swfobject.js"></script>
      <script type="text/javascript" src="/lib/js/jquery.uploadify.js"></script>
      {%if $lang.iso neq 'en'%}
      <!-- LOCALIZATION -->
      <script type="text/javascript" src="/lib/js/localization/messages_{%$lang.iso%}.js"></script>
      {%/if%}
      <script type="text/javascript">
         var $tabs;
         $(document).ready(function(){
            var removetab = function(tabselector, index) {
	           $(".removetab").click(function(){
	              $(tabselector).tabs('remove',index);
	           });
	        };

            $tabs = $('#tabedContent').tabs({
               tabTemplate: '<li><a href="#{href}">#{label}</a> <span class="ui-icon ui-icon-close removetab">Remove Tab</span></li>',
               add: function(event, ui)
               {
                  $tabs.tabs('select', '#' + ui.panel.id);
                  removetab($(this), ui.index);
               },
	           show: function(event, ui) {
                  removetab($(this), ui.index);
               }
            });

            $('#t_users_list').toggleCheckbox({
               button:'#b_check_users',
               uncheckText: "{%$TR->meccano->uncheckall|escape:'javascript'%}",
               checkText: "{%$TR->meccano->checkall|escape:'javascript'%}"
            });
            $('#t_groups_list').toggleCheckbox({
               button:'#b_check_groups',
               uncheckText: "{%$TR->meccano->uncheckall|escape:'javascript'%}",
               checkText: "{%$TR->meccano->checkall|escape:'javascript'%}"
            });
         });

         function EditUser(id, login) {
            id = id ? id : 0;
            tabTitle = id ? '{%$TR->meccano->edituserinfo|escape:"javascript"%}'+ (login ? ' ['+ login + ']' : '') : '{%$TR->meccano->adduser|escape:"javascript"%}';
            $tabs.tabs('add', '/admin/users?a=2&id='+id, tabTitle);
         }

         function EditGroup(id, title) {
            id = id ? id : 0;
            tabTitle = id ? '{%$TR->meccano->editgroup|escape:"javascript"%}'+ (title ? ' ['+ title +']' : '') : '{%$TR->meccano->addgroup|escape:"javascript"%}';
            $tabs.tabs('add', '/admin/users?a=11&id='+id, tabTitle);
         }

         function SwitchUserStatus(id, el)
         {
            var state = $('>img', el).attr('rel');
            var action = state == 'on' ? 5 : 4;
            $.ajax({
               type: "GET",
               url: "/admin/users.php",
               data: "a="+ action +"&id="+id,
               dataType: "text",
               success: function(json){
                  if(json)
                  {
                     var img = $('>img', el);
                     if(state == 'off')
                     {
                        img.attr('rel','on');
                        img.attr('src','/tpa/img/on.png');
                     } else
                     {
                        img.attr('rel','off');
                        img.attr('src','/tpa/img/off.png');
                     }
                  }
               }
            });
         }

      </script>
   </head>

   <body>

      {%if $error.status == true%}
      {%include file='servlet.error.html'%}
      {%/if%}

      <div id="tabedContent">

         <ul>
            <li><a href="#t_users_list"><span>{%$TR->meccano->users%}</span></a></li>
            <li><a href="#t_groups_list"><span>{%$TR->meccano->groups%}</span></a></li>
            <li><a href="#t_search"><span>{%$TR->meccano->search%}</span></a></li>
         </ul>


         <!-- USERS LIST TAB -->
         <div id="t_users_list">
            <div style='margin-bottom:10px;'>
               <input type='button' class='fl-left' value='{%$TR->meccano->adduser%}' onclick='EditUser(false, false);' />
               {%if $search%}
               <div class="fl-left notice" style="width:650px; padding: 7px 10px 0;">
                  <span class="warn">{%$TR->meccano->search_results%}: </span>
                  {%if $search.login%}{%$TR->meccano->login%}: <b>{%$search.login%}</b>; {%/if%}
                  {%if $search.email%}e-mail: <b>{%$search.email%}</b>; {%/if%}
                  {%if $search.group%}{%$TR->meccano->membership%}:{%foreach from=$search.group item='g' name='i'%}<b>{%$data.groups[$g].group%}</b>{%if !$smarty.foreach.i.last%}, {%/if%}{%/foreach%}{%/if%}
               </div>
               {%/if%}
               <input type='button' class='fl-right' value='{%$TR->meccano->editprofile%}' onclick='EditUser({%$authorizedUser->id%}, "{%$authorizedUser->login%}");' />
               <div class='clear'></div>
            </div>

            {%foreach from=$data.users item='u' name='i'%}
            {%if $smarty.foreach.i.first%}
            <form action='/admin/users.php' method='post'>
               <input type='hidden' name='a' value='6' />
               <table cellspacing='0' class='grid'>
                  <tr>
                     <th>{%$TR->meccano->login%}</th>
                     <th>{%$TR->meccano->name%}</th>
                     <th>e-mail</th>
                     <th>{%$TR->fields->vdate%}</th>
                     <th>{%$TR->meccano->wasloged%}</th>
                     <th>{%$TR->meccano->groups%}</th>
                     <th></th>
                     <th>{%$TR->meccano->delete%}</th>
                  </tr>
                  {%/if%}

                  <tr {%cycle values=",class='odd'"%}>
                     <td>{%$u->login%}</td>
                     <td>{%$u->name%} {%$u->surname%}</td>
                     <td>{%$u->email%}</td>
                     <td>{%$u->vdate%}</td>
                     <td>{%$u->lastloged|date_format:'%d.%m.%Y'%}</td>
                     <td id='tdg_{%$u->id%}'>{%$u->groupsByString%}</td>
                     <td class='ct'>
                        <a href='javascript:EditUser({%$u->id%}, "{%$u->login%}");'><img src='/tpa/img/pencil.gif' width='16' height='16' title='{%$TR->meccano->edituserinfo%}' /></a>
                        {%if $authorizedUser->id neq $u->id && $u->id neq 1%}
                           {%if $u->active%}
                           <a href="" onclick="SwitchUserStatus({%$u->id%}, this); return false;"><img src='/tpa/img/on.png' rel="on" /></a>
                           {%else%}
                           <a href="" onclick="SwitchUserStatus({%$u->id%}, this); return false;"><img src='/tpa/img/off.png' rel="off" /></a>
                           {%/if%}
                        {%/if%}
                     </td>
                     <td class='ct'>{%if $u->id neq 1%}<input type='checkbox' name='delu[]' value='{%$u->id%}' />{%/if%}</td>
                  </tr>

                  {%if $smarty.foreach.i.last%}
               </table>
               <hr>
                  <div class='fl-left'>
                     {%if $pages%}
                     {%$TR->meccano->records%} <span class="warn">{%$pages.show%}</span>
                     {%$TR->meccano->from%} <span class="warn">{%$pages.found%}</span>

                     <div class="paginator">
                     {%foreach from=$pages.links item='p'%}
                     {%if $p.current%}<span class="warn">{%$p.num%}</span>
                     {%else%}<a href="{%$p.href%}">{%$p.num%}</a>
                     {%/if%}
                     {%/foreach%}
                     </div>
                     {%/if%}
                  </div>
                  <div class='fl-right rt'>
                     <input type='button' value='{%$TR->meccano->checkall%}' id="b_check_users" /><br />
                     <input type='submit' value='{%$TR->meccano->delete%}' />
                  </div>
                  <div class='clear'></div>
            </form>
            {%/if%}
            {%foreachelse%}
            <div class='ct warn' style='padding:30px;'>{%$TR->meccano->norecords%}</div>
            {%/foreach%}

         </div>





         <!-- GROUPS LIST TAB -->
         <div id="t_groups_list">

            <div class='fl-left' style='margin-bottom:10px;'>
               <input type='button' value='{%$TR->meccano->addgroup%}' onclick='EditGroup(false);' />
            </div>

            <div class='clear'></div>
            {%foreach from=$data.groups item='g' name='i'%}
            {%if $smarty.foreach.i.first%}
            <form action='/admin/users.php' method='post'>
               <input type='hidden' name='a' value='12' />
               <table cellspacing="0" class="grid">
                  <col width="180" />
                  <tr>
                     <th>{%$TR->meccano->group%}</th>
                     <th>{%$TR->meccano->descr%}</th>
                     <th>{%$TR->meccano->rights%}</th>
                     <th></th>
                     <th>{%$TR->meccano->delete%}</th>
                  </tr>
                  {%/if%}
                  <tr {%cycle values=",class='odd'"%} id='r_group_{%$g.id%}'>
                     <td>{%$g.group%}</td>
                     <td class='notice'>{%$g.descr%}</td>
                     <td>{%', '|implode:$g.roles%}</td>
                     <td class='ct'><a href='javascript:EditGroup({%$g.id%}, "{%$g.group|escape:"javascript"%}");'><img src='/tpa/img/pencil.gif' width='16' height='16' title='{%$TR->meccano->editgroup%}' /></a></td>
                     <td class='ct'>{%if !$g.system%}<input type='checkbox' name='delg[]' value='{%$g.id%}' onchange='MarkTr(this);' />{%/if%}</td>
                  </tr>
                  {%if $smarty.foreach.i.last%}
               </table>
               <hr>
                  <div class='fl-left'>{%$TR->meccano->records%}: <b>{%$smarty.foreach.i.total%}</b></div>
                  <div class='fl-right rt'>
                     <input type='button' value='{%$TR->meccano->checkall%}' id="b_check_groups" /><br />
                     <input type='submit' value='{%$TR->meccano->delete%}' />
                  </div>
                  <div class='clear'></div>
            </form>
            {%/if%}
            {%foreachelse%}
            <div class='ct warn' style='padding:30px;'>{%$TR->meccano->norecords%}</div>
            {%/foreach%}
         </div>






         <!-- BOF SEARCH FORM -->
         <div id="t_search">
            <div>
               <form action='/admin/users.php' method='post'>
                  <table>
                     <tr>
                        <td class='rt'>
                           <label for='f_login'>{%$TR->meccano->login%}:</label></td>
                        <td>
                           <input type='text' name='s[login]' />
                        </td>
                     </tr>
                     <tr>
                        <td class='rt'>
                           <label for='f_email'>E-mail:</label>
                        </td>
                        <td>
                           <input type='text' name='s[email]' id='f_email' />
                        </td>
                     </tr>
                     <tr>
                        <td class='rt'>
                           {%$TR->meccano->membership%}:
                        </td>
                        <td>
                           {%foreach from=$data.groups item='g' name='i'%}
                           <input type='checkbox' name='s[group][]' value='{%$g.id%}' id='f_memb_{%$g.id%}' />
                           <label for='f_memb_{%$g.id%}'> - {%$g.group%}</label><br />
                           {%/foreach%}
                        </td>
                     </tr>
                     <tr>
                        <td></td>
                        <td>
                           <input type='submit' name='commit' id='commit' value=' {%$TR->meccano->search%} ' />
                        </td>
                     </tr>
                  </table>
               </form>
            </div>
         </div>
         <!-- EOF SEARCH FORM -->


      </div>

   </body>
</html>